<?php

!defined('IN_NOVA') && exit('Access Denied!');

class Application extends Base {

	public $m = NULL;

	public $p = NULL;

	function __construct() {
		// URL 解析
		$this->_U();

		if( $this->m == NULL ) {
			$this->m = 'index';
		}

		// 调用 init 函数进行初始化
		$this->init();
	}

	function __destruct() {
		//[DEBUG]
		if( defined( 'APP_DEBUG' ) && APP_DEBUG === TRUE ) {
			global $_NOVA,$log,$db;
			if( !isset( $log ) || !isset( $db ) ) {
				return;
			}

			// 内存占用
			if( function_exists( 'memory_get_usage' ) ) {
				$nova_mem = $_NOVA['RUN_MEM']['NOVA_END'] - $_NOVA['RUN_MEM']['NOVA_START'];
				$app_mem = memory_get_usage() - $_NOVA['RUN_MEM']['NOVA_END'];
			}
			// 运行耗时
			$nova_runtime = $_NOVA['RUN_TIME']['NOVA_END'] - $_NOVA['RUN_TIME']['NOVA_START'];
			$app_runtime = microtime( TRUE ) - $_NOVA['RUN_TIME']['NOVA_END'];

			$log->add( L( '_PAGE_MEMUSE_' ) . '[NOVA]' . $nova_mem / 1024 . 'KB。' . '[APP]' . $app_mem / 1024 . 'KB。', E_USER_NOTICE );
			$log->add( L( '_PAGE_RUNTIME_' ) . '[NOVA]' . number_format( $nova_runtime, 4 ) * 1000 . 'ms ( Core:' . number_format( $_NOVA['RUN_TIME']['CORE'], 4 ) * 1000 . 'ms' . ' )。' . '[APP]' . number_format( $app_runtime, 4 )  * 1000 . 'ms。', E_USER_NOTICE );
			$log->add( L( '_PAGE_QUERYNUM_' ) . $db->querynum . '。' . L( '_QUERY_RUNTIME_' ) . $db->querytime * 1000 . 'ms。', E_USER_NOTICE );
			if( defined( 'APP_TRACE' ) &&APP_TRACE === TRUE ) {
				@header("content-type: text/html; charset=utf-8");
				echo $log->trace();
			}
		}
		//[/DEBUG]
	}
	
	public function init() {
		// 空方法，留给子类继承
	}

}
?>
